<template>
  <div>
    <!-- 表格 -->
    <div class='tables'>
      <!-- table.style.height='100px' -->
      <el-table border size='mini' :data="commentData" height="calc(100vh - 150px)" stripe style="width: 100%">
        <!-- <el-table-column type=index  prop="" label="编号" width="180">
        </el-table-column> -->
        <el-table-column prop="id" label="编号" width="180">
        </el-table-column>
        <el-table-column prop="content" label="评论内容">
        </el-table-column>
        <el-table-column prop="commentTime" label="评论时间">
        </el-table-column>
        <el-table-column prop="orderId" label="产品ID">
        </el-table-column>
        <el-table-column prop="status" label="状态">
        </el-table-column>
        <el-table-column fixed="right" label="操作" width="180">
          <template slot-scope="scope">
            <el-button @click="toDelete(scope.row)" type="text" size="mini">删除</el-button>
            <el-button @click="toPass(scope.row)" type="text" size="mini">通过审核</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <!-- 分页 -->
    <div>
      <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page.sync="queryParams.page"
      :page-sizes="[5, 10, 15, 20]"
      :page-size="queryParams.pageSize"
      layout="total,sizes, prev, pager, next"
      :total="total">
    </el-pagination>
    </div>
  </div>
</template>

<script>
import { mapActions, mapGetters } from 'vuex';
import {deleteById} from '@/api/comment.js'
export default {
  data() {
    return {
      queryParams:{
        page:1,
        pageSize:10,
        status:''
      }
    };
  },
  computed: {
    ...mapGetters('comment',['total','commentData'])
  },
  methods: {
    ...mapActions('comment',['findAll']),
    toPass(){},
    //删除用户信息
    toDelete(row){
      console.log(row.id);
      //询问用户是否删除
       this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          //发请求删除
          deleteById({id:row.id}).then((res)=>{
            if(res.status===200){
              //提示删除成功，并且刷新数据
              this.$notify({
                title: '成功',
                message: '删除成功',
                type: 'success'
              });
              // this.queryParams.page=1;
              this.findAll(this.queryParams);
            }else{
              this.$notify({
                title: '失败',
                message: '删除失败',
                type: 'error'
              });
            }
          }).catch((err)=>{
            this.$notify({
                title: '失败',
                message: '删除失败',
                type: 'error'
              });
          })
          // this.$message({
          //   type: 'success',
          //   message: '删除成功!'
          // });
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });          
        });
    },
    //每页条数发生变化处理函数
    handleSizeChange(val) {
        // console.log(`每页 ${val} 条`);
        //改数据模型中的pageSize,设置page为1，发起请求
        this.queryParams.pageSize=val;
        this.queryParams.page=1;
        this.findAll(this.queryParams);
      },
      //当页码发生变化的时候
    handleCurrentChange(val) {
        console.log(`当前页: ${val}`);
        //修改数据模型中的数据，并发起请求
        this.queryParams.page=val;
        this.findAll(this.queryParams);
    }
  },
  created() {
    this.findAll(this.queryParams)
  },
  mounted() {},
};
</script>
<style lang="less" scoped>
</style>